if ($.cookie('LoginAccount')) {
  location.href = "./";
}
//平台、设备和操作系统
var platName = '';
var system = {
  win: false,
  mac: false,
  xll: false,
  ipad: false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
if (system.win || system.mac || system.xll || system.ipad) {
  // alert("PC");
  platName = 'PC';
} else {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == "micromessenger") {
    platName = '微信浏览器';
    // alert("微信浏览器");
  } else {
    platName = '手机';
    // alert("手机");
  }
}
$('#login').click(function() {
  if (!$('#XueHao').val()) {
    alert('请输入学/工号！');
    return;
  }
  if (!$('#password').val()) {
    alert('请输入密码！');
    return;
  }
  $.post('login.php', {
      XueHao: $('#XueHao').val(),
      password: $.md5($('#password').val())
    },
    function(data, textStatus, jqXHR) {
      if (data == '2') {
        alert('学/工号不存在！');
        return;
      }
      if (data == '3') {
        alert('密码错误！');
        return;
      }
      var data = JSON.parse(data);
      console.log(data.XingMing);
      var date = new Date();
      date.setTime(date.getTime() + (60 * 60 * 1000));
      $.cookie('LoginAccount', data.XueHao + '%' + data.XingMing + '%' + data.id + '%' + data.LeiBie + '%' +data.isDefaultPass, {
        expires: date
      });
      location.href = "./";
    }
  );
})
